﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HashTableTest
{
    class Program
    {
        static void Main(string[] args)
        {

            Hashtable hashtable = new Hashtable();

            hashtable.Add("苹果", "5");

            hashtable.Add("香蕉", "4");

            hashtable.Add("菠萝", 2);




            Console.WriteLine("请问要买什么,我们这有：");


            OutValues(hashtable);


            string input = Console.ReadLine();

            if (hashtable.ContainsKey(input))
            {
                Console.WriteLine("请问你要几个");

                int round = Convert.ToInt32(Console.ReadLine());

                var money = (int)hashtable[input] * round;

                Console.WriteLine("一共{0},拿钱拿钱", money);
            }
            else
            {
                Console.WriteLine("抱歉，我们这没有你需要的水果");
            }




            Console.WriteLine("天气不好下架水果");

            hashtable.Remove("香蕉");

            OutValues(hashtable);


            Console.ReadKey();
        }

        static void OutValues(ICollection collection)
        {
            if (((Hashtable)collection) is Hashtable)
            {
                foreach (DictionaryEntry item in collection)
                {
                    Console.Write(item.Key + " ");
                    Console.WriteLine(item.Value);
                }
            }
            else
            {
                foreach (var item in collection)
                {
                    Console.WriteLine(item);
                }
            }
        }

    }
}
